package com.gitee.kenewstar.utils.excel;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.OutputStream;
import java.lang.reflect.Field;
import java.util.List;

/**
 * <p>
 *     数据导出工具
 * </p>
 * @author kenewstar
 * @date 2021/7/9
 */
public abstract class DataExportUtil {

	public static final String DEFAULT_SHEET_NAME = "sheet";

	public static <T> OutputStream exportExcel(ExportParam exportParam, List<T> dataList) {

		// 获取所有的对象属性
		Field[] fields = exportParam.exportClass.getDeclaredFields();
		Workbook workbook = new XSSFWorkbook();

		Sheet sheet = workbook.createSheet(DEFAULT_SHEET_NAME);
		Row row = sheet.createRow(0);
		int index = 0;
		for (Field field : fields) {
			Cell cell = row.createCell(index++);
			cell.setCellValue(field.getName());
		}
		dataList.forEach(t -> {

		});
		return null;
	}
}
